using System;
using System.Collections.Generic;
using Castle.ActiveRecord;
using CosyTrade.Data;

namespace CosyTrade.Security
{
    [AddPropertyChangedNotifyInterface, PropertyChangedNotify]
    [Serializable, ActiveRecord("Module")]
    public class Module : BusinessObject
    {
        private readonly Guid primaryKey = Guid.NewGuid();
        private string moduleKey;
        private string moduleCaption;
        private byte[] moduleIcon;
        private int orderIndex;
        private readonly IList<Function> functions = new List<Function>();

        [PrimaryKey(PrimaryKeyType.Assigned, "ROWGUID", Access = PropertyAccess.NosetterCamelcase)]
        public Guid PrimaryKey
        {
            get { return primaryKey; }
        }

        [HasMany(typeof(Function), ColumnKey = "ModuleGuid", Table = "tbFunction", 
            Access = PropertyAccess.NosetterCamelcase, OrderBy = "OrderIndex", Where = "IsDeleteObject=0")]
        public IList<Function> Functions
        {
            get { return functions; }
        }

        [Property]
        public string ModuleKey
        {
            get { return moduleKey; }
            set { moduleKey = value; }
        }

        [Property]
        public string ModuleCaption
        {
            get { return moduleCaption; }
            set { moduleCaption = value; }
        }

        [Property]
        public byte[] ModuleIcon
        {
            get { return moduleIcon; }
            set { moduleIcon = value; }
        }

        [Property]
        public int OrderIndex
        {
            get { return orderIndex; }
            set { orderIndex = value; }
        }
    }
}